package Services

import(
	"github.com/gin-gonic/gin"
	"fmt"
	"net/http"
	"encoding/json"
	"gin/Databases"
	"gin/Common"
	"time"
)

// 宏观数据
func DisplayContinuousMarket(c *gin.Context) {
	time_now := time.Now()
    var date_str = time_now.Format("2006-01-02")
    fmt.Println("date_str, ", date_str)
	var macros []Common.MacroContinuousData
	sql := "select Fstart_date,Fend_date,Ftitle,Furl from macro_market_data where Fstart_date <= ? and Fend_date >= ? and Fstatus=1 order by Fstart_date;"
	err := Databases.Db.Select(&macros, sql, date_str, date_str)
	fmt.Println("sql, ", sql)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
	        "result": -1,
	        "msg":    "query fail",
	        "data": "{}",
	    })
		fmt.Println("exec failed, ", err)
		return
	}	

    str, _ := json.Marshal(macros)
    str_res := string(str)
    //fmt.Println("str:", str)
    c.JSON(http.StatusOK, gin.H{
        "result": 0,
        "msg":    "success",
        "data": str_res,
    })
}

